"""
Copyright (c) 2023 - present SKbioinfo
"""
import pandas as pd
from flask import request,jsonify,current_app
from flask_restful import Resource
from flask_jwt_extended import jwt_required
from apps.API.reportCreator.model import reportRecord
'''URL:/api/reportCreator/ReportRecord/ReportRecord'''
class interfaceReportRecord(Resource):
    @jwt_required()
    def get(self):
        try:
            limit=int(request.args.get('limit'))
            page=int(request.args.get('page'))
            run_id=request.args.get('run_id')
            query=reportRecord.query.filter(reportRecord.run_id==run_id).order_by(reportRecord.created_at.desc())
            pagination=query.paginate(page=page, per_page=limit, error_out=False)
            total_length=query.count()
            results=[item.to_dict() for item in pagination.items]
            response=jsonify({"total":total_length,"data":results})
            response.status=202
            return response  
        except Exception as e:
            response=jsonify({})
            response.status=404  
            return response
 
        


